﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CaiyinSoft.NetGather.Protocol;

namespace CaiyinSoft.NetGather.NetGatherLib.URLSource
{
    [Serializable]
    public class TextURLSource : URLSourceBase
    {

        public string URLListText { get; set; }
        public TextURLSource():base()
        {
            _InitParams();
        }

        private void _InitParams()
        {
            URLListText = "";
        }

        public override List<URLItem> GetURLCollection()
        {
            List<URLItem> URLCollection = new List<URLItem>();
            string[] urls = URLListText.Split(System.Text.Encoding.UTF8.GetChars(System.Text.Encoding.UTF8.GetBytes(Environment.NewLine)), StringSplitOptions.RemoveEmptyEntries);
            int i = 0;
            foreach (string url in urls)
            {
                URLCollection.Add(new URLItem { ID =i++, URL = url, Status = 0 });
            }
            return URLCollection;
        }

        public override void SetURLStatus(URLItem Item, URLItemStatus Status)
        {

        }

        [NonSerialized]
        private  TextURLSourceForm _editform;
        public override InnerFormBase GetEditForm()
        {
            if (_editform == null)
            {
                _editform = new TextURLSourceForm();
                _editform.InfoSaveEventHandler += (sender,args) => {
                    this.URLListText = _editform.URLListText;
                };
            }
            _editform.URLSource = this;
            return _editform;
        }

    }
}
